package atm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 取款界面
 */
public class GetPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private ImageIcon getpane = new ImageIcon("Tu/buttonGet.jpg");
    private JLabel accountLabel = new JLabel("取款");
    private JTextField accountField = new JTextField();
    private Font font = new Font("黑体",Font.BOLD,30);

    private JButton loginBtn = new JButton(getpane);


    public GetPanel(ATMFrame atmFrame){
        this.atmFrame=atmFrame;
        this.setLayout(null);
        accountLabel.setBounds(300,200,120,50);
        accountLabel.setFont(font);
        accountField.setBounds(400,200,250,50);    //输入空格
        accountLabel.setFont(font);

        loginBtn.setBounds(700,350,140,50);    //按钮
        loginBtn.addActionListener(this);



        this.add(accountLabel);
        this.add(accountField);
        this.add(loginBtn);



        this.setOpaque(false);





    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource()==loginBtn){
            User user = atmFrame.getLoginUser();
            try {
                user.setBlance(user.getBlance()-Double.parseDouble(accountLabel.getText()));
            }catch (NumberFormatException e1){
                System.out.println("");
            }
            atmFrame.switchPanel("menu");
        }

    }
}







